if exists('g:vtp_loaded')
  finish
else
  let g:vtp_loaded = 1
endif

function! s:initval(var, val) abort
  if !exists(a:var)
    exec 'let ' . a:var . '=' string(a:val)
  endif
endfunction

" 初始化设置
call s:initval('g:vtp_target_lang', 'en') "初始化语言
call s:initval('g:vtp_engine','bing') "初始化引擎
call s:initval('g:vtp_regexp', escape("'.*'", "'"))

nnoremap <plug>VTPTranslateCursorHover :<c-u>call vtp#translateCursorHover()<cr>
nnoremap <plug>VTPTranslateCursorReplace :<c-u>call vtp#translateCursorReplace()<cr>
vnoremap <plug>VTPTranslateRegexpReplace :<c-u>call vtp#regexpReplace()<cr>

command! -nargs=0 VTPTranslateCursorHover call vtp#translateCursorHover()
command! -nargs=0 VTPTranslateCursorReplace call vtp#translateCursorReplace()
command! -nargs=1 VTPChangeLang call vtp#changeTargetLang(<args>)

nmap <leader>t <plug>VTPTranslateCursorHover
nmap <leader>tr <plug>VTPTranslateCursorReplace
xmap <leader>tg <plug>VTPTranslateRegexpReplace
